//app.js

App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs);

  },
  setTabBar: function () {
    var tabBar = this.globalData.tabBar;
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
   
    _curPage.setData({
      tabBar: tabBar
    });
  },
  getUserInfo: function (cb) {

    var that = this;
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function () {
        
          wx.getUserInfo({
            success: function (res) {
             
              wx.setStorage({
                key: "hjk_scope",
                data: true
              });
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            },
            fail: function () {
             
              wx.openSetting({
                success: function (data) {
                  if (data) {
                    if (data.authSetting["scope.userInfo"] == true) {
                      var loginStatus = true;
                      //调用登录接口
                      wx.login({
                        success: function () {
                          
                          wx.getUserInfo({
                            success: function (res) {
                              
                              wx.setStorage({
                                key: "hjk_scope",
                                data: true
                              });
                              that.globalData.userInfo = res.userInfo
                              typeof cb == "function" && cb(that.globalData.userInfo)
                            },
                            fail: function () {
                             
                              
                            }
                          })
                        }
                      });
                    }
                  }
                },
                fail: function () {
                  console.info("设置失败返回数据");
                }
              });
            }
          })
        }
      });
    }
  },
  onShow: function () {
    
  },
  onHide: function () {
   
  },
  util: require('we7/resource/js/util.js'),
  globalData: {
    userInfo: null,
    globalset: null,
    tabBar: {
      "color": "#9B9DB1",
      "selectedColor": "#3cc51f",
      "borderStyle": "white",
      "list": [
        {
          "pagePath": "haojk/pages/index/index",
          "text": "首页",
          "iconPath": "haojk/images/tabbar-index-default.png",
          "selectedIconPath": "haojk/images/tabbar-index-selected.png"
        },
        {
          "pagePath": "haojk/pages/choiceness/index",
          "text": "京东券",
          "iconPath": "haojk/images/tabbar-buy-default.png",
          "selectedIconPath": "haojk/images/tabbar-buy-selected.png"
        },
        {
          "pagePath": "haojk/pages/my/index",
          "text": "我的",
          "iconPath": "haojk/images/tabbar-wode-default.png",
          "selectedIconPath": "haojk/images/tabbar-wode-selected.png"
        }
      ],
      "position": "bottom"
    }
  },

  //站点信息
  siteInfo: require('siteinfo.js')
})